home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / iconv8_s.arc / COMMON.ARC / TIME.C < prev   
Encoding:
C/C++ Source or Header  |  1990-03-28  |  7.5 KB  |  357 lines

  1. #include "..\h\config.h"
  2.  
  3. /*
  4.  * The following code is operating-system dependent [@time.01].  Include files
  5.  *  that are system-dependent.
  6.  */
  7.  
  8. #if PORT
  9.    /* probably needs something */
  10. Deliberate Syntax Error
  11. #endif                    /* PORT */
  12.  
  13. #if AMIGA
  14. #include "time.h"
  15. #endif                    /* AMIGA */
  16.  
  17. #if ATARI_ST
  18.    /* nothing is needed */
  19. #endif                    /* ATARI_ST */
  20.  
  21. #if HIGHC_386 || MVS || VM
  22. #include <time.h>
  23. #endif                    /* HIGHC_386 || MVS || ... */
  24.  
  25. #if MACINTOSH
  26. #if LSC
  27. #include <time.h>
  28. #endif                    /* LSC */
  29. #if MPW
  30. #include <types.h>
  31. #include "time.h"
  32. #include <OSUtils.h>
  33. #include <Events.h>
  34. #endif                    /* MPW */
  35. #endif                    /* MACINTOSH */
  36.  
  37. #if MSDOS
  38. #include <time.h>
  39. #if MICROSOFT
  40. #include <sys\types.h>
  41. #endif                    /* MICROSOFT */
  42. #endif                    /* MSDOS */
  43.  
  44. #if OS2
  45. #include <time.h>
  46. #include <sys\types.h>
  47. #endif                    /* OS2 */
  48.  
  49. #if UNIX
  50. #ifdef CRAY
  51. #define word    fubar_word
  52. #include <sys\types.h>
  53. #include <sys\times.h>
  54. #undef word
  55. #else                    /* CRAY */
  56. #include <sys\types.h>
  57. #include <sys\times.h>
  58. #endif                    /* CRAY */
  59. #include SysTime
  60. #endif                    /* UNIX */
  61.  
  62. #if VMS
  63. #include <types.h>
  64. #include <time.h>
  65. struct tms {
  66.     time_t    tms_utime;    /* user time */
  67.     time_t    tms_stime;    /* system time */
  68.     time_t    tms_cutime;    /* user time, children */
  69.     time_t    tms_cstime;    /* system time, children */
  70. };
  71. #endif                    /* VMS */
  72.  
  73. /*
  74.  * End of operating-system specific code.
  75.  */
  76.  
  77. static char *day[] = {
  78.    "Sunday", "Monday", "Tuesday", "Wednesday",
  79.    "Thursday", "Friday", "Saturday"
  80.    };
  81.  
  82. static char *month[] = {
  83.    "January", "February", "March", "April", "May", "June",
  84.    "July", "August", "September", "October", "November", "December"
  85.    };
  86.  
  87.  
  88. /*
  89.  * getitime - fill in a "struct cal_time" with information about the current
  90.  *  time and date.
  91.  */
  92. novalue getitime(ct)
  93. struct cal_time *ct;
  94.    {
  95.  
  96. /*
  97.  * The following code is operating-system dependent [@time.02]. Declarations
  98.  *  for getting time.
  99.  */
  100.  
  101. #if PORT
  102.    long time();
  103.    long xclock;
  104. Deliberate Syntax Error
  105. #endif                    /* PORT */
  106.  
  107. #if AMIGA || OS2 || UNIX || VMS
  108.    long time();
  109.    long xclock;
  110. #endif                    /* AMIGA || OS2 || UNIX || VMS */
  111.  
  112. #if ATARI_ST
  113.    struct tm {
  114.        short tm_year;
  115.        short tm_mon;
  116.        short tm_wday;
  117.        short tm_mday;
  118.        short tm_hour;
  119.        short tm_min;
  120.        short tm_sec;
  121.    };
  122.    long xclock;
  123. #endif                    /* ATARI_ST */
  124.  
  125. #if MSDOS
  126.    long xclock;
  127. #if LATTICE || MICROSOFT || TURBO
  128.    long time();
  129. #endif                    /* LATTICE || MICROSOFT || TURBO */
  130. #if MWC
  131.    time_t time();
  132. #endif                    /* MWC */
  133. #endif                    /* MSDOS */
  134.  
  135. #if HIGHC_386
  136.    long time();
  137.    time_t xclock;
  138. #endif                    /* HIGHC_386 */
  139.  
  140. #if MACINTOSH
  141. #if LSC
  142.    unsigned long xclock;
  143.    unsigned long time();
  144. #else                    /* LSC */
  145.    long xclock;
  146.    long time();
  147. #endif                    /* LSC */
  148. #endif                    /* MACINTOSH */
  149.  
  150. #if MVS || VM
  151.    time_t xclock;
  152. #endif                    /* MVS || VM */
  153.  
  154. /*
  155.  * End of operating-system specific code.
  156.  */
  157.  
  158.    struct tm *tbuf, *localtime();
  159. /*
  160.  * The following code is operating-system dependent [@time.03]. Code for
  161.  *  getting time.
  162.  */
  163.  
  164. #if PORT
  165.    time(&xclock);
  166.    tbuf = localtime(&xclock);
  167. Deliberate Syntax Error
  168. #endif                    /* PORT */
  169.  
  170. #if AMIGA || HIGHC_386 || MACINTOSH || MSDOS || OS2 || UNIX || VMS || MVS || VM
  171.    time(&xclock);
  172.    tbuf = localtime(&xclock);
  173. #endif                    /* AMIGA || HIGHC || ... */
  174.  
  175. #if ATARI_ST
  176.     tbuf = localtime(&xclock);
  177. #endif                    /* ATARI_ST */
  178.  
  179. /*
  180.  * End of operating-system specific code.
  181.  */
  182.  
  183.    ct->year = 1900 + tbuf->tm_year;
  184.    ct->month_no = tbuf->tm_mon+1;
  185.    ct->month_nm = month[tbuf->tm_mon];
  186.    ct->mday = tbuf->tm_mday;
  187.    ct->wday = day[tbuf->tm_wday];
  188.    ct->hour = tbuf->tm_hour;
  189.    ct->minute = tbuf->tm_min;
  190.    ct->second = tbuf->tm_sec;
  191.    return;
  192.    }
  193.  
  194. /*
  195.  * getctime - fill a buffer with the "ctime" representation of the current
  196.  *  time and date. The buffer must be at least 26 characters.
  197.  */
  198. novalue getctime(sbuf)
  199. char *sbuf;
  200.    {
  201.    struct cal_time ct;
  202.  
  203.    getitime(&ct);
  204.    sprintf(sbuf, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", ct.wday, ct.month_nm,
  205.       ct.mday, ct.hour, ct.minute, ct.second, ct.year);
  206.    return;
  207.    }
  208.  
  209. /*
  210.  * millisec - returns execution time in milliseconds. Time is measured
  211.  *  from the fucntions's first call. The granularity of the time is
  212.  *  generally more than one millisecond and on some systems it my only
  213.  *  be accurate to the second.
  214.  */
  215. long millisec()
  216.    {
  217.    static int first_time = 1;
  218.  
  219. /*
  220.  * The following code is operating-system dependent [@time.04]. Declarations
  221.  *   that are system-dependent.
  222.  */
  223.  
  224. #if PORT
  225.    static long starttime;
  226.    long time();
  227. Deliberate Syntax Error
  228. #endif                    /* PORT */
  229.  
  230. #if AMIGA || ATARI_ST || OS2
  231.    static long starttime;
  232.    long time();
  233. #endif                    /* AMIGA || ATARI_ST || OS2 */
  234.  
  235. #if HIGHC_386
  236.    static time_t hc_strtime;
  237.    time_t hc_curtime;
  238.    long time();
  239. #endif                    /* HIGHC_386 */
  240.  
  241. #if MACINTOSH
  242.    static long starttime;
  243. #endif                    /* MACINTOSH */
  244.  
  245. #if MSDOS
  246.    static long starttime;
  247. #if LATTICE || MICROSOFT || TURBO
  248.    long time();
  249. #endif                    /* LATTICE || MICROSOFT || TURBO */
  250. #if MWC
  251.    time_t time();
  252. #endif                    /* MWC */
  253. #endif                    /* MSDOS */
  254.  
  255. #if MVS || VM
  256.    static clock_t starttime;
  257. #endif                                  /* MVS || VM */
  258.  
  259. #if UNIX || VMS
  260.    struct tms tp;
  261.    static long starttime;
  262. #endif                    /* UNIX || VMS */
  263.  
  264. /*
  265.  * End of operating-system specific code.
  266.  */
  267.  
  268.    if (first_time) {
  269.       first_time = 0;
  270.  
  271. /*
  272.  * The following code is operating-system dependent [@time.05].  Get start
  273.  *  time.
  274.  */
  275.  
  276. #if PORT
  277.       /* needs something */
  278. Deliberate Syntax Error
  279. #endif                    /* PORT */
  280.  
  281. #if AMIGA  || ATARI_ST || MSDOS || OS2
  282.       time(&starttime);    /* note: this obtains time in various units */
  283. #endif                    /* AMIGA || ATARI_ST || MSDOS */
  284.  
  285. #if HIGHC_386
  286.       time(&hc_strtime);
  287. #endif                    /* HIGHC_386 */
  288.  
  289. #if MACINTOSH
  290.       starttime = TickCount();    /* 60 ticks / second */
  291. #endif                    /* MACINTOSH */
  292.  
  293. #if MVS || VM
  294.       starttime = clock();        /* microseconds */
  295. #endif                    /* MVS || VM */
  296.  
  297. #if UNIX || VMS
  298.       times(&tp);
  299.       starttime = tp.tms_utime;
  300. #endif                    /* UNIX || VMS */
  301.  
  302. /*
  303.  * End of operating-system specific code.
  304.  */
  305.  
  306.       return 0L;
  307.       }
  308.    else {    /* not first time */
  309. /*
  310.  * The following code is operating-system dependent [@time.06].  Get time.
  311.  */
  312.  
  313. #if PORT
  314.    /* needs something */
  315. Deliberate Syntax Error
  316. #endif                    /* PORT */
  317.  
  318. #if AMIGA || MSDOS || OS2
  319.       return 1000 * (time(NULL) - starttime);
  320. #endif                    /* AMIGA || MSDOS || OS2 */
  321.  
  322. #if ATARI_ST
  323.       return (time(NULL) - starttime) / 10;
  324. #endif                    /* ATARI_ST */
  325.  
  326. #if HIGHC_386
  327.       time(&hc_curtime);
  328.       return 1000 * (long)difftime(hc_curtime,hc_strtime);
  329. #endif                    /* HIGHC_386 */
  330.  
  331. #if MACINTOSH
  332.       return 1000 * ((extended)(TickCount() - starttime) / (extended)Hz);
  333. #endif                    /* MACINTOSH */
  334.  
  335. #if MVS || VM
  336. #if SASC
  337. #ifndef CLOCKS_PER_SEC       /* if late addition to the Std not there */
  338. #define CLOCKS_PER_SEC CLK_TCK     /* use the old name */
  339. #endif                    /* CLOCKS_PRE_SEC */
  340.       return (1000.0/CLOCKS_PER_SEC) * (clock() - starttime);
  341. #endif                    /* SASC */
  342. #ifdef WATERLOO_C_V3_0
  343.       return ((long)clock() - starttime) / 1000;
  344. #endif                    /* WATERLOO_C_V3_0 */
  345. #endif                    /* MVS || VM */
  346.  
  347. #if UNIX || VMS
  348.       times(&tp);
  349.       return 1000 * ((tp.tms_utime - starttime) / (double)Hz);
  350. #endif                    /* UNIX || VMS */
  351.  
  352. /*
  353.  * End of operating-system specific code.
  354.  */
  355.       }
  356.    }
  357.